package com.cloud.pole.shop.controller.goods;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.util.RegexUtils;
import com.cloud.pole.shop.model.entity.order.ShopOrderComment;
import com.cloud.pole.shop.model.vo.goods.GoodsCollectionVo;
import com.cloud.pole.shop.model.vo.order.ShopOrderCommentVo;
import com.cloud.pole.shop.service.goods.GoodsCollectionService;
import com.github.pagehelper.PageInfo;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;

/*
*2019年3月26日
*cloud-shop
*author:frank-chen
*/
@Controller
@Slf4j
@RequestMapping("/goodsCollection/front")
public class GoodsCollectionController {

	@Autowired
	private GoodsCollectionService goodsCollectionService;
	
	@ResponseBody
	@RequestMapping("/getGoodsCollectionList")
    public ApiRestResponse<List<GoodsCollectionVo>> getGoodsCollectionList(
    		@RequestHeader(defaultValue = "") String token,
    		@RequestParam(name="pageSize", defaultValue="") String pageSize,
    		@RequestParam(name="pageNum", defaultValue="") String pageNum){   	
    	try {
			ParamException.err(StringUtils.isBlank(pageSize), "pageSize不能为空");
			ParamException.err(!RegexUtils.isPositiveInteger(pageSize), "pageSize错误");
			
			ParamException.err(StringUtils.isBlank(pageNum), "pageNum不能为空");
			ParamException.err(!RegexUtils.isPositiveInteger(pageNum), "pageNum错误");

			PageInfo<GoodsCollectionVo> pageInfo = goodsCollectionService.getPageGoodsCollectionList(token, Integer.parseInt(pageNum), Integer.parseInt(pageSize));
			List<GoodsCollectionVo> list = pageInfo.getList();
			return ApiRestResponse.successOfPage(CommonConstants.STATUS_OK_MESSAGE, (int)pageInfo.getPages(), pageInfo.getPageNum(), pageInfo.getPageSize(), list);
      	} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
}
